import constants from "~/common/constants.js";
const common = {
    getLocalToken: () => {
        let token = ''
        try {
            token = localStorage.getItem(constants.LocalTokenKey) || ''
        } catch(e){}
        return token
    },
    setLocalToken: (token) => {
        try {
            localStorage.setItem(constants.LocalTokenKey, token)
        } catch(e){}
    },
    removeLocalToken: () => {
        try {
            localStorage.removeItem(constants.LocalTokenKey)
        } catch(e){}
    },
    getLocalUser: () => {
        let user = {}
        try {
            user = localStorage.getItem(constants.LocalUserKey) || ''
            if (user) {
                user = JSON.parse(user)
            }
        } catch(e){}
        return user
    },
    setLocalUser: (user) => {
        if (!user) {
            return
        }
        try {
            localStorage.setItem(constants.LocalUserKey, JSON.stringify(user))
        } catch(e){}
    },
    removeLocalUser: () => {
        try {
            localStorage.removeItem(constants.LocalUserKey)
        } catch(e){}
    },
}
export default common
